//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.ScientificWorkflow.ManagementStudioControls.RegistryManagerModule
{
    using System.Windows;
    using System.Windows.Controls;
    using Microsoft.Research.ScientificWorkflow.ManagementStudioModels;
    using System.Windows.Input;
    using System.Collections.Generic;

	/// <summary>
	/// Interaction logic for Window1.xaml
	/// </summary>
	public partial class SearchUser : Window
	{
		public SearchUser()
		{
			this.InitializeComponent();
            this.txtUserName.Focus();
            this.brdrHeader.MouseLeftButtonDown += delegate(object sender, MouseButtonEventArgs e) { this.DragMove(); };
            // Insert code required on object creation below this point.
		}

        private void OnUserSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            SearchUserPresenter presenter = this.DataContext as SearchUserPresenter;
            if (presenter != null )
            {
                ListBox usersList = sender as ListBox ;
                if(usersList != null)
                {
                    presenter.SelectUserModel.Clear();
                    foreach (SearchUserModel model in usersList.SelectedItems)
                    {
                        presenter.SelectUserModel.Add(model);
                    }
                }
            }
        }

        private void OnUserNameChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
        {
            SearchUserPresenter presenter = this.DataContext as SearchUserPresenter;
            if (presenter != null && presenter.NameChangesCommand != null)
            {
                presenter.NameChangesCommand.Execute(null);
            }
        }
	}
}